myApp.run(function ($rootScope,   $state,   $stateParams,$serAccessSignin, ngDialog,$localStorage) {
        $rootScope.$state = $state;
        $rootScope.$stateParams = $stateParams;
        $rootScope.ngDialog = ngDialog;
        $rootScope.moment = moment;
        // $rootScope.moment.lang('zh-cn');
        //判断用户是否登录，如果未登录跳转到登录页
        $rootScope.$on('$stateChangeSuccess',userLogin); //stateChangeSuccess 过度完成触发
        function userLogin(event,toState){
            if(toState.name.search(/access.signin/)==-1){
                if(!$serAccessSignin.getUser()){
                    $state.go('access.signin');
                }
            }else {
                $localStorage.userInfo = {};
            }
        }
    })    
    .config(function($stateProvider, $urlRouterProvider,JQ_CONFIG, MODULE_CONFIG) {
        $urlRouterProvider.otherwise("/app/home");
        $stateProvider
            .state('app', {
                abstract: true,
                url: '/app',
                templateUrl: 'tpl/app.html'
            })
            .state('app.home', {
                url: "/home",
                templateUrl: 'tpl/home/home.html',
                resolve:{},
                controller:'homeController as ctrl'
            })
            .state('access', {
                url: '/access',
                template: '<div ui-view class="fade-in-right-big smooth"></div>'
            })
            .state('access.signin', {
                url: '/signin',
                templateUrl: 'tpl/access/access_signin.html',
                resolve:{},
                controller:'loginController as ctrl'
            })
            .state('access.signup', {
                url: '/signup/:code',
                templateUrl: 'tpl/access/signup.html',
                resolve:{},
                controller:'signupController as ctrl'
            })
            .state('app.dashboard', {                 //概览
                url: '/dashboard',
                templateUrl: 'tpl/dashboard/index.html',
                //resolve: load(['js/directives/ui-jq.js','js/controllers/dashboard/dashboard.js']),
                controller:'dashboardCtl as ctrl'
            })
            .state('app.catalog', {
                url: "/catalog",
                templateUrl: 'tpl/catalog/catalog.html',
                resolve:load( ['angularFileUpload','js/controllers/catalog/catalog.js'] ),
                controller:'catalogController as ctrl'
            })
            .state('app.admin', {
                url: "/admin",
                templateUrl: 'tpl/admin/admin.html',
                resolve:{}
            })
            .state('app.attr', {
                url: "/attr",
                templateUrl: 'tpl/attr/attr.html',
                resolve:{},
                controller:'attrController as ctrl'
            })
            .state('app.addAttr', {
                url: "/addAttr",
                templateUrl: 'tpl/attr/addAttr.html',
                resolve:{},
                controller:'addAttrController as ctrl'
            })
            .state('app.changeAttr', {
                url: "/changeAttr?id&name&alias&backend_show",
                templateUrl: 'tpl/attr/changeAttr.html',
                resolve:load( ['angularFileUpload','js/controllers/attr/changeAttr.js'] ),
                controller:'changeAttrController as ctrl'
            })
            .state('app.addAttrValue', {
                url: "/addAttrValue",
                templateUrl: 'tpl/attr/addAttrValue.html',
                resolve:{},
                controller:'addAttrValueController as ctrl'
            })
            .state('app.product', {
                url: "/product",
                templateUrl: 'tpl/product/product.html',
                resolve:{},
                controller:'productController as ctrl'
            })
            .state('app.additem', {
                url: "/additem",
                templateUrl: 'tpl/product/additem.html',
                resolve:load( ['angularFileUpload','js/controllers/product/additem.js'] ),
                controller:'additemController as ctrl'
            })
            .state('app.changeitem', {
                url: "/changeitem?id",
                templateUrl: 'tpl/product/changeitem.html',
                resolve:load( ['angularFileUpload','js/controllers/product/changeitem.js'] ),
                controller:'changeitemController as ctrl'
            })
            .state('app.order', {
                url: "/order",
                template:'<div ui-view></div>'
            })
            .state('app.order.orderList', {
                url: "/orderList",
                templateUrl: 'tpl/orderList/orderList.html',
                resolve:{},
                controller:'orderListController as ctrl'
            })
    
            .state('app.order.orderDetail', {
                url: "/orderDetail/:id",
                templateUrl: 'tpl/orderList/orderDetail.html',
                resolve:{},
                controller:'orderDetailController as ctrl'
            })
            .state('app.order.express', {
                url: "/express/:id",
                templateUrl: 'tpl/orderList/express.html',
                resolve:{},
                controller:'expressDetailController as ctrl'
            })
            .state('app.express', {
                url: "/express",
                template:'<div ui-view></div>'
            })
            .state('app.express.expressList', {
                url: "/expressList",
                templateUrl: 'tpl/express/expressList.html',
                resolve:{},
                controller:'expressListController as ctrl'
            })
            .state('app.express.ShippingMethod', {
                url: "/ShippingMethod",
                templateUrl: 'tpl/express/ShippingMethod.html',
                resolve:{},
                controller:'ShippingMethodController as ctrl'
            })
            .state('app.coupon', {
                url: "/coupon",
                template:'<div ui-view></div>'
            })
            .state('app.coupon.userCouponList', {
                url: "/userCouponList",
                templateUrl: 'tpl/coupon/userCouponList.html',
                resolve:{},
                controller:'userCouponListController as ctrl'
            })
            .state('app.coupon.couponList', {
                url: "/couponList",
                templateUrl: 'tpl/coupon/couponList.html',
                resolve:{},
                controller:'couponListController as ctrl'
            })


            .state('app.slider', {  //轮播图
                url: "/slider",
                template:'<div ui-view></div>',
            })
            .state('app.slider.slider', {
                url: "/sliderList",
                templateUrl: 'tpl/slider/slider.html',
                resolve:load( ['angularFileUpload','js/controllers/slider/slider.js'] ),
                controller:'sliderListController as ctrl'
            })
            .state('app.advert', {  //广告图
                url: "/advert",
                template:'<div ui-view></div>',
            })
            .state('app.advert.advert', {
                url: "/advertList",
                templateUrl: 'tpl/advert/advert.html',
                resolve:load( ['angularFileUpload','js/controllers/advert/advert.js'] ),
                controller:'advertListController as ctrl'
            })
            .state('app.point', {  //积分
                url: "/point",
                template:'<div ui-view></div>',
            })
            .state('app.point.point', {
                url: "/pointList",
                templateUrl: 'tpl/point/point.html',
                resolve:load( ['angularFileUpload','js/controllers/point/point.js'] ),
                controller:'pointListController as ctrl'
            })
            .state('app.point.reviews', {
                url: "/reviews",
                templateUrl: 'tpl/point/reviews.html',
                resolve:load( ['angularFileUpload','js/controllers/point/reviews.js'] ),
                controller:'reviewsListController as ctrl'
            })
            .state('app.brand', {  //品牌
                url: "/brand",
                template:'<div ui-view></div>',
            })
            .state('app.brand.brand', {
                url: "/brandList",
                templateUrl: 'tpl/brand/brand.html',
                resolve:load( ['angularFileUpload','js/controllers/brand/brand.js'] ),
                controller:'brandListController as ctrl'
            })
            .state('app.tags', {  //标签
                url: "/tags",
                template:'<div ui-view></div>',
            })
            .state('app.tags.tags', {
                url: "/tagsList",
                templateUrl: 'tpl/tags/tags.html',
                resolve:load( ['angularFileUpload','js/controllers/tags/tags.js'] ),
                controller:'tagsListController as ctrl'
            })
            .state('app.email', {
                url: "/email",
                template:'<div ui-view></div>'
            })
            .state('app.email.email', {
                url: "/emailList",
                templateUrl: 'tpl/email/email.html',
                resolve:{},
                controller:'emailListController as ctrl'
            })

            .state('app.email.addEmail', {
                url: "/addEmail/:id",
                templateUrl: 'tpl/email/addEmail.html',
                resolve:{},
                controller:'emailListController as ctrl'
            })
            .state('app.email.upEmail', {
                url: "/upEmail/:id",
                templateUrl: 'tpl/email/upEmail.html',
                resolve:{},
                controller:'upEmailController as ctrl'
            })
            .state('app.cleanCache', {
                url: "/cleanCache",
                templateUrl: 'tpl/cleanCache/cleanCache.html',
                resolve:{},
                controller:'cleanCacheController as ctrl'
            })
            .state('app.AfterService', {
                url: "/AfterService",
                template:'<div ui-view></div>'
            })
            .state('app.AfterService.AfterService', {
                url: "/afterServiceList",
                templateUrl: 'tpl/afterService/afterServiceList.html',
                resolve:{},
                controller:'AfterServiceListController as ctrl'
            })
            .state('app.AfterService.AfterServiceDetail', {
                url: "/afterServiceDetail/:id",
                templateUrl: 'tpl/afterService/afterServiceDetail.html',
                resolve:{},
                controller:'AfterServiceDetailController as ctrl'
            })
            .state('app.users', {
                url: "/users",
                templateUrl: 'tpl/users/users.html',
                resolve:{},
                controller:'usersController as ctrl'
            })
            .state('app.list', { //admin权限管理列表
                url: '/list',
                templateUrl: 'tpl/manager/list.html'
            })
            .state('app.save', { //admin权限管理添加角色
                url: '/save/:id',
                templateUrl: 'tpl/manager/save.html'
            })
            .state('app.node', { //admin权限管理节点
                url: '/node',
                template: '<div ui-view></div>'
               // resolve:load( [ 'js/controllers/manager/nodeAdmin.js'] )
            })
            .state('app.node.list', { //admin权限管理节点列表
                url: '/list',
                templateUrl: 'tpl/manager/nodeList.html'
            })
            .state('app.node.addController', { //admin权限管理添加控制器节点
                url: '/addController/:id',
                templateUrl: 'tpl/manager/addController.html'
            })
            .state('app.node.addFunction', { //admin权限管理添加方法节点
                url: '/addFunction/:id',
                templateUrl: 'tpl/manager/addFunction.html'
            })
            .state('app.node.tree', { //admin权限管理节点树
                url: '/tree',
                templateUrl: 'tpl/manager/nodeTree.html'
            })
        function load(srcs, callback) {
            return {
                deps: ['$ocLazyLoad', '$q',
                    function( $ocLazyLoad, $q ){
                        var deferred = $q.defer();//创建一个延迟对象，表示将在未来完成这个任务
                        var promise  = false;
                        srcs = angular.isArray(srcs) ? srcs : srcs.split(/\s+/);
                        if(!promise){
                            promise = deferred.promise;//deferred对象的承诺对象
                        }
                        angular.forEach(srcs, function(src) {
                            promise = promise.then( function(){
                                if(JQ_CONFIG[src]){
                                    return $ocLazyLoad.load(JQ_CONFIG[src]);
                                }
                                angular.forEach(MODULE_CONFIG, function(module) {
                                    if( module.name == src){
                                        name = module.name;
                                    }else{
                                        name = src;
                                    }
                                });
                                return $ocLazyLoad.load(name);
                            } );
                        });
                        deferred.resolve();
                        return callback ? promise.then(function(){ return callback(); }) : promise;
                    }]
            }
        }
    });